#pragma once 
#include <Arduino.h>
#include "Modbus_RTU.h"

class CODSensor
{
public:
    enum FuncCode{ReadFuncCode = 0x03, //读取功能码
                    SetFuncCOde = 0x06, //写入功能码
                    ReadCOD_REG = 0x0000, // COD 浓度值地址
                    ReadPH_REG = 0x0001,    // PH值地址
                    ReadTemperature_REG = 0x0002, // 温度地址
                    SetTemperatureOffset_REG = 0x0050,  //温度偏移值
                    SetPHOffset_REG = 0x0051,  //PH偏移值
                    SetCODOffset_REG = 0x0052,  //COD偏移值
                    DevID_REG = 0x07D0,  //设备ID
                    DevBaudRate_REG = 0x07D1, //设备波特率
                    };
    enum _BaudRate {
        BaudRate_1200 = 0x0007,  //波特率-写入用
        BaudRate_2400 = 0x0000,
        BaudRate_4800 = 0x0001,
        BaudRate_9600 = 0x0002,
        BaudRate_19200 = 0x0003,
        BaudRate_38400 = 0x0004,
        BaudRate_57600 = 0x0005,
        BaudRate_115200 = 0x0006
    };
    float ReadPH(void);
    float ReadTemperature(void);
    float ReadCOD(void);
    bool initCODSensor(Modbus_RTU * _modbus);
private:
    unsigned char DevID;
    Modbus_RTU * modbus;
    bool SetFunc(CODSensor::FuncCode func, short SetData);
    short ReadFun(CODSensor::FuncCode func);
};